// Code file original author: Martin Lapierre, http://devinstinct.com

using System;
using System.Collections.Generic;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation.Properties;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using EntLibContrib.Validation.Validators;

namespace EntLibContrib.Validation.Configuration
{
    /// <summary>
    /// Configuration object to describe an instance of class <see cref="CollectionCountValidator"/>.
    /// </summary>
    /// <remarks>
    /// Spin-off of the StringLengthValidatorData class.
    /// </remarks>
    /// <seealso cref="CollectionCountValidator"/>
    /// <seealso cref="ValidatorData"/>
    public class CollectionCountValidatorData : RangeValidatorData<int>
    {
        /// <summary>
        /// <para>Initializes a new instance of the <see cref="CollectionCountValidatorData"/> class.</para>
        /// </summary>
        public CollectionCountValidatorData()
        { }

        /// <summary>
        /// <para>Initializes a new instance of the <see cref="CollectionCountValidatorData"/> class with a name.</para>
        /// </summary>
        /// <param name="name">The name for the instance.</param>
        public CollectionCountValidatorData(string name)
            : base(name, typeof(CollectionCountValidator))
        { }

        /// <summary>
        /// Creates the <see cref="CollectionCountValidator"/> described by the configuration object.
        /// </summary>
        /// <param name="targetType">The type of object that will be validated by the validator.</param>
        /// <returns>The created <see cref="CollectionCountValidator"/>.</returns>
        protected override Validator DoCreateValidator(Type targetType)
        {
            return new CollectionCountValidator(this.LowerBound,
                this.LowerBoundType,
                this.UpperBound,
                this.UpperBoundType,
                Negated);
        }
    }
}